<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="python,argparse," />








  <link rel="shortcut icon" type="image/x-icon" href="/blog/favicon.ico?v=5.1.0" />






<meta name="description" content="前言python是一门非常方便的脚本语言，那么我们如何在运行脚本语言的时候向程序传参，并且使用类似-h的功能呢？这就是今天的argparse库的用法。 基本使用在脚本中向程序传递参数。argparse_test.pyimport argparseparser = argparse.ArgumentParser()parser.add_argument(&quot;name&quot;)args = parser.pa">
<meta name="keywords" content="python,argparse">
<meta property="og:type" content="article">
<meta property="og:title" content="python argparse用法总结">
<meta property="og:url" content="https://gitee.com/shuhao/2018/02/27/python-argparse用法总结/index.html">
<meta property="og:site_name" content="Niki">
<meta property="og:description" content="前言python是一门非常方便的脚本语言，那么我们如何在运行脚本语言的时候向程序传参，并且使用类似-h的功能呢？这就是今天的argparse库的用法。 基本使用在脚本中向程序传递参数。argparse_test.pyimport argparseparser = argparse.ArgumentParser()parser.add_argument(&quot;name&quot;)args = parser.pa">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-02-28T01:02:10.288Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="python argparse用法总结">
<meta name="twitter:description" content="前言python是一门非常方便的脚本语言，那么我们如何在运行脚本语言的时候向程序传参，并且使用类似-h的功能呢？这就是今天的argparse库的用法。 基本使用在脚本中向程序传递参数。argparse_test.pyimport argparseparser = argparse.ArgumentParser()parser.add_argument(&quot;name&quot;)args = parser.pa">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Mist',
    sidebar: {"position":"right","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://gitee.com/shuhao/2018/02/27/python-argparse用法总结/"/>





  <title> python argparse用法总结 | Niki </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?cb9f0585e406f878cb2f29c89ad3cdb7";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>










  
  
    
  

  <div class="container one-collumn sidebar-position-right page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Niki</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">天道酬勤</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-categories"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://gitee.com/shuhao/blog/2018/02/27/python-argparse用法总结/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Fang ShuHao">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/head.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Niki">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                python argparse用法总结
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-02-27T08:50:18+08:00">
                2018-02-27
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/python/" itemprop="url" rel="index">
                    <span itemprop="name">python</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>python是一门非常方便的脚本语言，那么我们如何在运行脚本语言的时候向程序传参，并且使用类似-h的功能呢？这就是今天的argparse库的用法。</p>
<h2 id="基本使用"><a href="#基本使用" class="headerlink" title="基本使用"></a>基本使用</h2><p>在脚本中向程序传递参数。argparse_test.py<br><figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">import</span> argparse</span><br><span class="line"></span><br><span class="line">parser = argparse.ArgumentParser()</span><br><span class="line">parser.add_argument(<span class="string">"name"</span>)</span><br><span class="line"></span><br><span class="line">args = parser.parse_args()</span><br><span class="line">print(args.name)</span><br></pre></td></tr></table></figure></p>
<p>运行脚本<br><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">&gt; python argparse_test.py kobe</span><br><span class="line">kobe</span><br><span class="line"></span><br><span class="line">&gt; python argparse_test.py -h</span><br><span class="line">usage: argparse_test.py [-h] name</span><br><span class="line"></span><br><span class="line">positional arguments:</span><br><span class="line">  name</span><br><span class="line"></span><br><span class="line">optional arguments:</span><br><span class="line">  -h, --help  show this help message and exit</span><br></pre></td></tr></table></figure></p>
<p>可以看到argparse自动为我们生成了帮助文档，通过-h就能查看脚本的帮助文档。帮组文档大概分成两部分，一部分为<strong><em>必须字段</em></strong>：name，另一部分为<strong><em>可选字段</em></strong>：-h、-help</p>
<p>如果我们没有传echo参数，会怎样?<br><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">&gt; python argparse_test.py</span><br><span class="line">usage: argparse_test.py [-h] name</span><br><span class="line">argparse_test.py: error: the following arguments are required: name</span><br></pre></td></tr></table></figure></p>
<p>可以看到没有传入<strong>name</strong>的参数，报错，所以<strong>name</strong>必须输入！</p>
<h2 id="positional-arguments，optional-arguments"><a href="#positional-arguments，optional-arguments" class="headerlink" title="positional arguments，optional arguments"></a>positional arguments，optional arguments</h2><ul>
<li><p>positional arguments(必须参数)：不带“-”或“–”前缀的参数。执行脚本时，也不需要输入参数名，根据参数的位置，为指定位置的参数赋值（位置默认按照定义的顺序）。该类型参数默认为必选。不输入执行脚本报错。</p>
</li>
<li><p>optional arguments(可选参数)：</p>
</li>
</ul>
<ol>
<li>通过“-”指定的短参数：如-h</li>
<li>通过“–”指定的长参数：如–help<br>这类参数默认为非必选。输入参数时，需要先输入参数名如 -interest basketball</li>
</ol>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line">parser.add_argument(<span class="string">"name"</span>)</span><br><span class="line">parser.add_argument(<span class="string">"age"</span>)</span><br><span class="line"></span><br><span class="line">parser.add_argument(<span class="string">"-i"</span>,<span class="string">"--interest"</span>) <span class="comment">#爱好</span></span><br><span class="line"></span><br><span class="line">args = parser.parse_args()</span><br><span class="line"><span class="keyword">if</span> args.interest:</span><br><span class="line">	print(<span class="string">"name is %s, age is %s, interest is %s"</span> % (args.name,args.age, args.interest))</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line">	print(<span class="string">"name is %s, age is %s"</span> % (args.name,args.age))</span><br></pre></td></tr></table></figure>
<p>我们可以看出差别主要在参数名，<strong>必填参数<em>名没有前缀-或者–</em>，*</strong>选填参数前面有前缀-或–<em>*</em></p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">&gt; python argparse_test.py kobe 40</span><br><span class="line">name is kobe, age is 40</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">&gt; python argparse_test.py kobe 40 -i basketball</span><br><span class="line">name is kobe, age is 40, interest is basketball</span><br><span class="line"></span><br><span class="line">&gt; python argparse_test.py kobe 40 --interest basketball</span><br><span class="line">name is kobe, age is 40, interest is basketball</span><br></pre></td></tr></table></figure>
<ul>
<li>python获取参数是都是不需要前缀的长名称。如：args.interest ,不能使用args.i获取兴趣参数。</li>
</ul>
<h2 id="设置参数类型-type"><a href="#设置参数类型-type" class="headerlink" title="设置参数类型  type"></a>设置参数类型  type</h2><p>之前的age参数，我们用的是字符串，不是int类型，那么如何设置传入参数的类型呢？<br><figure class="highlight python"><table><tr><td class="code"><pre><span class="line">parser.add_argument(<span class="string">"age"</span>, type=int)</span><br><span class="line">args = parser.parse_args()</span><br><span class="line">print(type(args.age))</span><br><span class="line">print(isinstance(age, str))</span><br></pre></td></tr></table></figure></p>
<p>运行一下得到结果为：<br><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">&gt; python argparse_test.py kobe 40 --interest basketball</span><br><span class="line">&lt;class &apos;int&apos;&gt;</span><br><span class="line">False</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">&gt; python argparse_test.py kobe a  --interest basketball</span><br><span class="line">usage: argparse_test.py [-h] [-i INTEREST] name age</span><br><span class="line">argparse_test.py: error: argument age: invalid int value: &apos;a&apos;</span><br></pre></td></tr></table></figure></p>
<p>可以看到age的类型已经改为了int类型。如果传入的参数不是int类型的话。例如a，则系统抛出异常。</p>
<h2 id="设置系统的默认值-default"><a href="#设置系统的默认值-default" class="headerlink" title="设置系统的默认值   default"></a>设置系统的默认值   default</h2><p>如果我们这个程序是用在篮球学校的，那么大部分用户的爱好肯定是篮球了，那么我们是不是可以设置interest的默认值为basketball。不需要每次都传入。<br><figure class="highlight python"><table><tr><td class="code"><pre><span class="line">parser.add_argument(<span class="string">'-i'</span>,<span class="string">'-interest'</span>, default=<span class="string">"basketball"</span>)</span><br><span class="line">args = parser.parse_args()</span><br><span class="line">print(args.interest)</span><br></pre></td></tr></table></figure></p>
<p>运行一下结果为：<br><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">&gt; python argparse_test.py kobe 40</span><br><span class="line">name is kobe, age is 40, interest is basketball</span><br></pre></td></tr></table></figure></p>
<p>从打印的结果可以看出，我们没有传interest的值，但是interest采用了默认值：basketball</p>
<h2 id="设置参数的帮助信息-help"><a href="#设置参数的帮助信息-help" class="headerlink" title="设置参数的帮助信息   help"></a>设置参数的帮助信息   help</h2><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">&gt; python argparse_test.py -h</span><br><span class="line">usage: argparse_test.py [-h] [-i INTEREST] name age</span><br><span class="line"></span><br><span class="line">positional arguments:</span><br><span class="line">  name</span><br><span class="line">  age</span><br><span class="line"></span><br><span class="line">optional arguments:</span><br><span class="line">  -h, --help            show this help message and exit</span><br><span class="line">  -i INTEREST, --interest INTEREST</span><br></pre></td></tr></table></figure>
<p>从-h帮组信息中我们可以看到 -h,–help 后面还有一句话：“show this help message and exit” 这类似于是对-h这个参数的解释了。那么为了开发出更友好的脚本，让用户的输入更清晰友好，我们是不是也应该给脚本的输入参数添加解释性的语句呢？<br><figure class="highlight python"><table><tr><td class="code"><pre><span class="line">parser.add_argument(<span class="string">"name"</span>, help=<span class="string">"姓名"</span>)</span><br><span class="line">parser.add_argument(<span class="string">"age"</span>, type=int, help=<span class="string">"年龄"</span>)</span><br><span class="line">parser.add_argument(<span class="string">"-i"</span>,<span class="string">"--interest"</span>, default=<span class="string">"basketball"</span>, help=<span class="string">"兴趣爱好"</span>)</span><br></pre></td></tr></table></figure></p>
<p>再次查看帮组信息<br><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">&gt;python argparse_test.py -h</span><br><span class="line">usage: argparse_test.py [-h] [-i INTEREST] name age</span><br><span class="line"></span><br><span class="line">positional arguments:</span><br><span class="line">  name                  姓名</span><br><span class="line">  age                   年龄</span><br><span class="line"></span><br><span class="line">optional arguments:</span><br><span class="line">  -h, --help            show this help message and exit</span><br><span class="line">  -i INTEREST, --interest INTEREST</span><br><span class="line">                        兴趣爱好</span><br></pre></td></tr></table></figure></p>
<h2 id="标记参数-store-”store-true”"><a href="#标记参数-store-”store-true”" class="headerlink" title="标记参数 store=”store_true”"></a>标记参数 store=”store_true”</h2><p>如果我们需要的是一个标记参数，不需要该参数传值，类似于-h，如果输入这个参数，进行业务处理，没有输入则不做处理，要怎么设置呢？<br><figure class="highlight python"><table><tr><td class="code"><pre><span class="line">parser.add_argument(<span class="string">"--flag"</span>, store=<span class="string">"store_true"</span>)</span><br><span class="line">args = parser.parse_args()</span><br><span class="line"><span class="keyword">if</span> args.flag:</span><br><span class="line">	print(<span class="string">"参数中输入了flag！"</span>)</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line">	print(<span class="string">"参数中没有flag参数！"</span>)</span><br></pre></td></tr></table></figure></p>
<p>查看运行结果<br><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">&gt; python argparse_test.py </span><br><span class="line">参数中没有flag参数！</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">&gt; python argparse_test.py --flag</span><br><span class="line">参数中输入了flag！</span><br></pre></td></tr></table></figure></p>
<h2 id="可选值choices"><a href="#可选值choices" class="headerlink" title="可选值choices=[]"></a>可选值choices=[]</h2><p>如果我们要加一个参数性别，并且我们只允许输入 男（man），女(female)两种参数。要怎么设置？<br><figure class="highlight python"><table><tr><td class="code"><pre><span class="line">parser.add_argument(<span class="string">"--gender"</span>, choices=[<span class="string">"man"</span>, <span class="string">"female"</span>], default=<span class="string">"man"</span>, help=<span class="string">"性别"</span>)</span><br></pre></td></tr></table></figure></p>
<p>查看运行结果<br><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">&gt; python argparse_test.py kobe 40 --gender man</span><br><span class="line">name is kobe, age is 40, interest is basketball</span><br><span class="line">参数中没有flag参数！</span><br><span class="line">性别是：man</span><br><span class="line"></span><br><span class="line">&gt;python argparse_test.py kobe 40 --gender m</span><br><span class="line">usage: argparse_test.py [-h] [-i INTEREST] [--flag] [--gender &#123;man,female&#125;]</span><br><span class="line">                        name age</span><br><span class="line">argparse_test.py: error: argument --gender: invalid choice: &apos;m&apos; (choose from &apos;man&apos;, &apos;female&apos;)</span><br></pre></td></tr></table></figure></p>
<p>可以看出如果–gender的值不是[“man”,”female”]会抛异常。</p>
<h2 id="必须参数-required"><a href="#必须参数-required" class="headerlink" title="必须参数 required"></a>必须参数 required</h2><p>之前我们说参数前缀为“-”或“”–“的参数为非必须，那么如何设置其为必须参数。例如：设置性别gender为必须参数<br><figure class="highlight python"><table><tr><td class="code"><pre><span class="line">parser.add_argument(<span class="string">"--gender"</span>, choices=[<span class="string">"man"</span>, <span class="string">"female"</span>], default=<span class="string">"man"</span>, required=<span class="keyword">True</span>, help=<span class="string">"性别"</span>)</span><br></pre></td></tr></table></figure></p>
<p>查看运行结果：<br><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">&gt; python argparse_test.py kobe 40</span><br><span class="line">usage: argparse_test.py [-h] [-i INTEREST] [--flag] --gender &#123;man,female&#125;</span><br><span class="line">                        [-l | -r] [--user USER] [--password PASSWORD]</span><br><span class="line">                        name age</span><br><span class="line">argparse_test.py: error: the following arguments are required: --gender</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">&gt; python argparse_test.py kobe 40 --gender man</span><br><span class="line">name is kobe, age is 40, interest is basketball</span><br><span class="line">参数中没有flag参数！</span><br><span class="line">性别是：man</span><br></pre></td></tr></table></figure></p>
<h2 id="互斥参数"><a href="#互斥参数" class="headerlink" title="互斥参数"></a>互斥参数</h2><p>如果两个参数中只允许输入一个，如何设置？<br><figure class="highlight python"><table><tr><td class="code"><pre><span class="line">exclusive_group = parser.add_mutually_exclusive_group()</span><br><span class="line">exclusive_group.add_argument(<span class="string">"-l"</span>,<span class="string">"--left"</span>, action=<span class="string">"store_true"</span>)</span><br><span class="line">exclusive_group.add_argument(<span class="string">"-r"</span>,<span class="string">"--right"</span>, action=<span class="string">"store_true"</span>)</span><br></pre></td></tr></table></figure></p>
<p>查看运行结果：<br><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">&gt; python argparse_test.py kobe 40 -l</span><br><span class="line">name is kobe, age is 40, interest is basketball</span><br><span class="line">参数中没有flag参数！</span><br><span class="line">性别是：man</span><br><span class="line">输入left!</span><br><span class="line"></span><br><span class="line">&gt; python argparse_test.py kobe 40 -r</span><br><span class="line">name is kobe, age is 40, interest is basketball</span><br><span class="line">参数中没有flag参数！</span><br><span class="line">性别是：man</span><br><span class="line">输入right!</span><br><span class="line"></span><br><span class="line">&gt; python argparse_test.py kobe 40 -r -l</span><br><span class="line">usage: argparse_test.py [-h] [-i INTEREST] [--flag] [--gender &#123;man,female&#125;]</span><br><span class="line">                        [-l | -r]</span><br><span class="line">                        name age</span><br><span class="line">argparse_test.py: error: argument -l/--left: not allowed with argument -r/--right</span><br></pre></td></tr></table></figure></p>
<p>可以看出，如果同时输入-r -l 程序抛异常。不允许同时出现。</p>
<h2 id="必须同时出现的参数"><a href="#必须同时出现的参数" class="headerlink" title="必须同时出现的参数"></a>必须同时出现的参数</h2><p>(还未找出方法…知道的小伙伴麻烦发个邮件1542115262@qq.com谢谢！^……^)</p>
<h2 id="程序的说明"><a href="#程序的说明" class="headerlink" title="程序的说明"></a>程序的说明</h2><p>参数的说明，我们可以通过help类指定，那么这个程序的说明如何指定？<br><figure class="highlight python"><table><tr><td class="code"><pre><span class="line">parser = argparse.ArgumentParser(description=<span class="string">"argparse使用demo"</span>)</span><br></pre></td></tr></table></figure></p>
<p><a href="https://gitee.com/shuhao/python_demo/blob/master/argparse_test.py">示例代码</a></p>
<blockquote>
<blockquote>
<p>参考<br><a href="https://www.jianshu.com/p/fef2d215b91d" target="_blank" rel="external">python argparse用法总结</a><br><a href="https://docs.python.org/2/library/argparse.html" target="_blank" rel="external">https://docs.python.org/2/library/argparse.html</a></p>
</blockquote>
</blockquote>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blog/tags/python/" rel="tag"># python</a>
          
            <a href="/blog/tags/argparse/" rel="tag"># argparse</a>
          
        </div>
      

      
        
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2018/02/12/java并发编程之AQS/" rel="next" title="java并发编程之AQS">
                <i class="fa fa-chevron-left"></i> java并发编程之AQS
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2018/02/27/python中函数参数传递和可变长参数（args和kwargs）/" rel="prev" title="python中函数参数传递和可变长参数（\*args和\*\*kwargs）">
                python中函数参数传递和可变长参数（\*args和\*\*kwargs） <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>

          
          </div>
          


          
  <div class="comments" id="comments">
    
      <div id="lv-container" data-id="city" data-uid="MTAyMC8zNjY5NS8xMzIzMA=="></div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/blog/images/head.jpg"
               alt="Fang ShuHao" />
          <p class="site-author-name" itemprop="name">Fang ShuHao</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
          
        </div>
        <nav class="site-state motion-element">
        
          
            <div class="site-state-item site-state-posts">
              <a href="/blog/archives">
                <span class="site-state-item-count">135</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-categories">
              <a href="/blog/categories">
                <span class="site-state-item-count">35</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/blog/tags">
                <span class="site-state-item-count">93</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#前言"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#基本使用"><span class="nav-number">2.</span> <span class="nav-text">基本使用</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#positional-arguments，optional-arguments"><span class="nav-number">3.</span> <span class="nav-text">positional arguments，optional arguments</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#设置参数类型-type"><span class="nav-number">4.</span> <span class="nav-text">设置参数类型  type</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#设置系统的默认值-default"><span class="nav-number">5.</span> <span class="nav-text">设置系统的默认值   default</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#设置参数的帮助信息-help"><span class="nav-number">6.</span> <span class="nav-text">设置参数的帮助信息   help</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#标记参数-store-”store-true”"><span class="nav-number">7.</span> <span class="nav-text">标记参数 store=”store_true”</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#可选值choices"><span class="nav-number">8.</span> <span class="nav-text">可选值choices=[]</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#必须参数-required"><span class="nav-number">9.</span> <span class="nav-text">必须参数 required</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#互斥参数"><span class="nav-number">10.</span> <span class="nav-text">互斥参数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#必须同时出现的参数"><span class="nav-number">11.</span> <span class="nav-text">必须同时出现的参数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#程序的说明"><span class="nav-number">12.</span> <span class="nav-text">程序的说明</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Fang ShuHao</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    
    
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  




  
  <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.0"></script>



  



  




	





  





  





  
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
  



  
  

  

  

  

  


  

</body>
</html>
